<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="app">
        <button @click="btnPre()">上一张</button>
        <img :src="img[index]" alt="" style="height: 120px;">
        <button @click="btnNext()">下一张</button>
    </div>

    <script>
        let vue=new Vue({
            el:'#app',
            data(){
                return{
                    img:["./images/1.png","./images/2.png","./images/3.png","./images/4.png","./images/5.png"],
                    index:'0'
                }
            },
            methods:{
                btnPre:function(){
                    console.log("上一张");
                    if(this.index<=0){
                        this.index=this.img.length-1;
                    }else{
                        this.index--;
                    }
                },
                btnNext:function(){
                    console.log("下一张");
                    
                    if(this.index>=this.img.length-1){
                        this.index=0;
                        console.log(this.index);
                    }else{
                        this.index++;
                    }
                }
            }
        })
    </script>
</body>
</html>